home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Networking / Network Watch (DMZ) v1.3 / dmz.a next >
Encoding:
Text File  |  1994-06-16  |  6.9 KB  |  244 lines  |  [TEXT/MPS ]

  1. ;_________________________________________________________________________
  2. ;
  3. ; dmz.a
  4. ;_________________________________________________________________________
  5. ;
  6. ; DTS Code Sample
  7. ;    
  8. ; ©1990 Apple Computer, Inc.
  9. ;
  10. ; 3/7/90 - 10/26/90 pvh
  11. ;
  12. ;_________________________________________________________________________
  13.  
  14.     PRINT    PUSH,OFF        ; don't print any of this stuff
  15.  
  16.     INCLUDE 'QuickEqu.a'
  17.     INCLUDE 'ToolEqu.a'
  18.     INCLUDE 'SysEqu.a'
  19.     INCLUDE 'Traps.a'
  20.     INCLUDE 'ATalkEqu.a'
  21.     INCLUDE    'SysErr.a'        
  22.     
  23.     PRINT    POP                ; restore the PRINT options    
  24.  
  25. ;--------------------------------------
  26. ; myVBLSpinInstall
  27. ;
  28. ; 10/90 pvh
  29. ;
  30. ; I hated the ToolLib spinning cursor routines enough to make up my own.  Those routines
  31. ; are fine if you base your spinning cursor off a tight loop where you can continuously call the 
  32. ; routines to actually spin the cursor.  In my case that library was not ideal, so instead
  33. ; I just threw ('slapped' might be the better term) together a VBL task that spins the cursor
  34. ; instead (ala MacApp).
  35. ;
  36. ; This routine & the clean up routine that follows are pretty mcuh self explanatory.  4 cursors
  37. ; are preloaded & locked so they'll be sure to be available when the VBL task is called.  The 
  38. ; task is set up and moved into the application's heap.  The task itself checks a locally saved
  39. ; variable for the cursor ID, loads in that cursor and sets that cursor as the current one if
  40. ; the cursor state is not currently busy (by checking CrsrBusy).
  41. ; When the task finishes, global references to the VBL task are used in the clean up routine
  42. ; (stopAndRemoveSpinningCursor) to remove the task & associated buffers.  The cursors are also
  43. ; released from memory here.
  44. ;
  45. ; 10/16/90 pvh
  46. ;
  47. ; gMac was imported originally to help support color cursors within this task, but that endeavor
  48. ; was turning out to be too much of a hack (even for me), so it's staying around as a remanant of
  49. ; that failed attempt just to mark another one of my failures.  :-)
  50.  
  51. spinGlobals    RECORD    0        ; this is our global data storage
  52. gtheTaskPtr        DS.L    1        ; pointer to hold task itself
  53. gtheVBLPtr        DS.L    1        ; pointer for VBL task record
  54.           ENDR
  55.  
  56.         EXPORT    (sg):DATA
  57.  
  58. sg            DS    spinGlobals        ; globals for spin cursor
  59.  
  60.  
  61. myVBLSpinInstall    PROC     EXPORT
  62.         IMPORT    gMac : DATA
  63.      
  64. StackFrame    RECORD    {A6Link},DECR        ; build a stack frame record
  65. ParamBegin    EQU    *                        ; start listing parameters here
  66. ParamSize    EQU    ParamBegin-*            ; size of all the passed parameters
  67. RetAddr     DS.L    1                    ; place holder for return address
  68. A6Link        DS.L    1                    ; place holder for A6 link
  69. taskSize     DS.L    1                     ; size of our VBL task
  70. curses        DS.L    4                    ; handle for our cursor
  71. cursType    DS.L    1
  72. LocalSize    EQU     *                    ; size of all the local variables
  73.         ENDR
  74.     
  75.                 WITH    StackFrame, SysEnvRec        ; cover our local stack frame
  76.                 LINK    A6,#LocalSize                ; allocate our local stack frame
  77.                     
  78.                 ; pre-load in the resources to make sure they are around 
  79.                 CLR.L    -(sp)                        ; make space on the stack for result
  80.                 MOVE.L    #'CURS', cursType(a6)        ; another remanant from color stuff (don't ask)
  81.                 MOVE.L    cursType(a6), -(sp)
  82.                 MOVE    #1001, -(sp)
  83.                 _GetResource
  84.                 MOVE.L    (sp)+, curses(a6)
  85.                 MOVE.L    curses(a6), a0
  86.                 _HLock
  87.     
  88.                 CLR.L    -(sp)                        ; make space on the stack for result
  89.                 MOVE.L    cursType(a6), -(sp)
  90.                 MOVE    #1002, -(sp)
  91.                 _GetResource
  92.                 MOVE.L    (sp)+, curses+4(a6)
  93.                 MOVE.L    curses+4(a6), a0
  94.                 _HLock
  95.     
  96.                 CLR.L    -(sp)                        ; make space on the stack for result
  97.                 MOVE.L    cursType(a6), -(sp)
  98.                 MOVE    #1003, -(sp)
  99.                 _GetResource
  100.                 MOVE.L    (sp)+, curses+8(a6)
  101.                 MOVE.L    curses+8(a6), a0
  102.                 _HLock
  103.     
  104.                 CLR.L    -(sp)                        ; make space on the stack for result
  105.                 MOVE.L    cursType(a6), -(sp)
  106.                 MOVE    #1004, -(sp)
  107.                 _GetResource
  108.                 MOVE.L    (sp)+, curses+12(a6)
  109.                 MOVE.L    curses+12(a6), a0
  110.                 _HLock
  111.     
  112.                 BRA.S     theTaskEnd
  113.                 
  114.                 ; actual VBL Task
  115. theTaskBegin
  116.                 MOVEM.L    a0-a6/d0-d7, -(sp)        ; save 
  117.                 BRA.S    afterStorage
  118. A5Storage
  119.                 DC.L    0
  120. afterStorage
  121.                 ; reset the vbl count
  122.                 MOVE.W     #5, vblCount(a0)    
  123.                 
  124.                 ; restore A5 for globals we may have
  125.                 LEA        A5Storage, a0
  126.                 MOVE.L    (a0), a5
  127.                 BRA.S    xxx
  128. cursorStorage                
  129.                 DC.W    $03E9                        ; storage for cursor type, start with first cursor ID
  130. xxx                
  131.                 LEA        cursorStorage, a0
  132.                 ADD.W    #1, (a0)
  133.                 MOVE.W    (a0), d0
  134.                 CMP.W    #1005, d0
  135.                 BLT.S    doCursor
  136.                 
  137.                 MOVE.W    #1001, (a0)                    ; start over with cursor type #1001
  138.                 MOVE.W    #1001, d0                    ; it needs to be in d0
  139. doCursor        
  140.                 CLR.L    -(a7)                        ; make some space for return
  141.                 MOVE.W    d0, -(a7)                    ; move in cursor type
  142.                 _GetCursor
  143.                 MOVE.L    (a7)+, a0                    ; move handle into a0
  144.                 BEQ.S    vblExit                        ; test for nil handle
  145.                 tst.b    CrsrBusy                    ; cursor drawing as we speak?  then split.
  146.                 BNE.S    vblExit
  147.                 MOVE.L    (a0), -(a7)                    ; deref and push on stack
  148.                 _SetCursor            
  149. vblExit
  150.                 MOVEM.L     (sp)+, a0-a6/d0-d7            ; restore 
  151.                 rts
  152. theTaskEnd
  153.                 
  154.                 ; VBL initialization code
  155.                 LEA        theTaskEnd, a0                ; address of tail of task
  156.                 LEA        theTaskBegin, a1            ; head of task
  157.                 MOVE.L    a0, d0                        ; get size of task
  158.                 SUB.L    a1, d0
  159.                 MOVE.L    d0, taskSize(a6)
  160.                 
  161.                 LEA        A5Storage, a0                ; put current A5 into our storage area in code
  162.                 MOVE.L    CurrentA5, (a0)
  163.             
  164.                 ; set up VBL record
  165.                 MOVE.L    #vblPhase+2, d0                ; size of VBLTask
  166.                 _NewPtr    
  167.                 MOVE.L    a0, sg.gtheVBLPtr(a5)
  168.                 
  169.                 ; setup block of memory to hold task itself (in our heap, not the System heap)
  170.                 MOVE.L    taskSize(a6), d0
  171.                 _NewPtr
  172.                 MOVE.L    a0, sg.gtheTaskPtr(a5)
  173.             
  174.                 ; move the task code into block in heap
  175.                 LEA        theTaskBegin, a0            ; head of task
  176.                 MOVE.L    sg.gTheTaskPtr(a5), a1
  177.                 MOVE.L    taskSize(a6), d0
  178.                 _BlockMove
  179.             
  180.                 MOVE.L     sg.gtheTaskPtr(a5), a1
  181.                 MOVE.L    sg.gtheVBLPtr(a5), a0
  182.                 MOVE.L    a1, vblAddr(a0)                ; a1 contains address of moved TheTask
  183.                 MOVE.W     #vType, qType(a0)
  184.                 MOVE.W     #10, vblCount(a0)
  185.                 MOVE.W     #4, vblPhase(a0)            ; whatever
  186.                 _VInstall
  187.     
  188. Exit            UNLK    A6                ; destroy the link
  189.                 MOVEA.L    (SP)+,A0        ; pull off the return address
  190.                 ADDA.L    #ParamSize,SP    ; strip all of the caller's parameters
  191.                 JMP    (A0)                ; return to the caller
  192.             
  193.         ENDP
  194.  
  195. ;--------------------------------------
  196. ; this routine disposes of the VBL spinning cursor task & removes memory allocated for the
  197. ; task.  also unloads the cursors from the heap.
  198.  
  199. stopAndRemoveSpinningCursor    PROC     EXPORT
  200.     
  201.         IMPORT    gtheTaskPtr : DATA
  202.         IMPORT    gtheVBLPtr : DATA
  203.              
  204.                 MOVE.L    sg.gtheVBLPtr, a0
  205.                 _VRemove
  206.                 
  207.                 MOVE.L    sg.gtheVBLPtr, a0
  208.                 _DisposPtr
  209.                 
  210.                 MOVE.L    sg.gtheTaskPtr, a0
  211.                 _DisposPtr
  212.                 
  213.                 ; unload the cursors 
  214.                 CLR.L    -(sp)
  215.                 MOVE.L    #'CURS', -(sp)
  216.                 MOVE    #1001, -(sp)
  217.                 _GetResource
  218.                 _ReleaseResource
  219.     
  220.                 CLR.L    -(sp)
  221.                 MOVE.L    #'CURS', -(sp)
  222.                 MOVE    #1002, -(sp)
  223.                 _GetResource
  224.                 _ReleaseResource
  225.     
  226.                 CLR.L    -(sp)
  227.                 MOVE.L    #'CURS', -(sp)
  228.                 MOVE    #1003, -(sp)
  229.                 _GetResource
  230.                 _ReleaseResource
  231.     
  232.                 CLR.L    -(sp)
  233.                 MOVE.L    #'CURS', -(sp)
  234.                 MOVE    #1004, -(sp)
  235.                 _GetResource
  236.                 _ReleaseResource
  237.  
  238.                 rts
  239.                 
  240.         ENDP
  241. ;--------------------------------------
  242.         END                ; end of this source file
  243.